package com.lling.oscbugly;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;


public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        findViewById(R.id.demo_011).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                test011();
            }
        });
        findViewById(R.id.demo_032).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                test032();
            }
        });
    }

    //    #011.
    //    java.util.ConcurrentModificationException
    //    java.util.ConcurrentModificationException
    //    java.util.ArrayList$ArrayListIterator.next(ArrayList.java:573)
    //            org.cocos2dx.lib.Cocos2dxSound.unloadEffect(Cocos2dxSound.java:126)
    //            org.cocos2dx.lib.Cocos2dxHelper.unloadEffect(Cocos2dxHelper.java:228)
    //            org.cocos2dx.lib.Cocos2dxRenderer.nativeRender(Native+Method)
    //            org.cocos2dx.lib.Cocos2dxRenderer.onDrawFrame(Cocos2dxRenderer.java:95)
    //            android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1523)
    //            android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1240)
    private void test011() {
        List<String> list = new ArrayList<String>();
        list.add("a");
        list.add("b");
        list.add("c");
        list.add("d");
        for (String str : list) {
            if(str.equals("c")){
                list.remove(str);
            }else{
                Log.d("TAG", str);
            }
        }
    }

//    #032. java.util.ConcurrentModificationException
//    java.util.ConcurrentModificationException
//    java.util.HashMap$HashIterator.nextEntry(HashMap.java:806)
//            java.util.HashMap$EntryIterator.next(HashMap.java:843)
//            java.util.HashMap$EntryIterator.next(HashMap.java:841)
//            org.cocos2dx.lib.Cocos2dxSound.stopAllEffects(Cocos2dxSound.java:229)
//            org.cocos2dx.lib.Cocos2dxActivity.stopAllEffects(Cocos2dxActivity.java:184)
//            org.cocos2dx.lib.Cocos2dxRenderer.nativeOnPause(Native+Method)
//            org.cocos2dx.lib.Cocos2dxRenderer.handleOnPause(Cocos2dxRenderer.java:145)
//            org.cocos2dx.lib.Cocos2dxGLSurfaceView$4.run(Cocos2dxGLSurfaceView.java:268)
//            android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1463)
//            android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1240)
    private void test032() {
        Map<String, String> map = new HashMap<String, String>();
        map.put("a", "1");
        map.put("b", "2");
        map.put("c", "3");
        map.put("d", "4");
        Iterator iter = map.entrySet().iterator();
        while (iter.hasNext()) {
            Map.Entry entry = (Map.Entry) iter.next();
            String key = entry.getKey().toString();
            String val = entry.getValue().toString();
            if("c".equals(key)) {
                map.remove(key);
            }
            Log.d("TAG", val);
        }
    }

}
